package reamodel.diagram.part;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;

import reamodel.REAModel;
import reamodel.ReamodelPackage;
import reamodel.diagram.edit.parts.CommitmentAgentEditPart;
import reamodel.diagram.edit.parts.CommitmentResourceEditPart;
import reamodel.diagram.edit.parts.DecrementCommitmentEditPart;
import reamodel.diagram.edit.parts.DecrementCommitmentFulfillEditPart;
import reamodel.diagram.edit.parts.DecrementCommitmentNameEditPart;
import reamodel.diagram.edit.parts.DecrementCommitmentSpecifyEditPart;
import reamodel.diagram.edit.parts.DecrementEconomicEventEditPart;
import reamodel.diagram.edit.parts.DecrementEconomicEventNameEditPart;
import reamodel.diagram.edit.parts.DecrementEconomicEventTypeEditPart;
import reamodel.diagram.edit.parts.DecrementEconomicEventTypeNameEditPart;
import reamodel.diagram.edit.parts.DecrementEconomicEventTypeTypifyEditPart;
import reamodel.diagram.edit.parts.DualityLabelEditPart;
import reamodel.diagram.edit.parts.DualityTypeLabelEditPart;
import reamodel.diagram.edit.parts.EconomicAgentEditPart;
import reamodel.diagram.edit.parts.EconomicAgentNameEditPart;
import reamodel.diagram.edit.parts.EconomicAgentTypeEditPart;
import reamodel.diagram.edit.parts.EconomicAgentTypeNameEditPart;
import reamodel.diagram.edit.parts.EconomicAgentTypeTypifyEditPart;
import reamodel.diagram.edit.parts.EconomicResourceEditPart;
import reamodel.diagram.edit.parts.EconomicResourceInflowLabelEditPart;
import reamodel.diagram.edit.parts.EconomicResourceNameEditPart;
import reamodel.diagram.edit.parts.EconomicResourceOutflowLabelEditPart;
import reamodel.diagram.edit.parts.EconomicResourceTypeEditPart;
import reamodel.diagram.edit.parts.EconomicResourceTypeNameEditPart;
import reamodel.diagram.edit.parts.EconomicResourceTypeTypifyEditPart;
import reamodel.diagram.edit.parts.FulfillLabel2EditPart;
import reamodel.diagram.edit.parts.FulfillLabelEditPart;
import reamodel.diagram.edit.parts.IncrementCommitmentEditPart;
import reamodel.diagram.edit.parts.IncrementCommitmentFulfillEditPart;
import reamodel.diagram.edit.parts.IncrementCommitmentNameEditPart;
import reamodel.diagram.edit.parts.IncrementCommitmentReciprocityEditPart;
import reamodel.diagram.edit.parts.IncrementCommitmentSpecifyEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventDualityEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventNameEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventTypeDualityTypeEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventTypeEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventTypeNameEditPart;
import reamodel.diagram.edit.parts.IncrementEconomicEventTypeTypifyEditPart;
import reamodel.diagram.edit.parts.InflowEditPart;
import reamodel.diagram.edit.parts.InflowNameEditPart;
import reamodel.diagram.edit.parts.InflowTypeEditPart;
import reamodel.diagram.edit.parts.InflowTypeLabelEditPart;
import reamodel.diagram.edit.parts.InflowTypeNameEditPart;
import reamodel.diagram.edit.parts.OutflowEditPart;
import reamodel.diagram.edit.parts.OutflowNameEditPart;
import reamodel.diagram.edit.parts.OutflowTypeEditPart;
import reamodel.diagram.edit.parts.OutflowTypeLabelEditPart;
import reamodel.diagram.edit.parts.OutflowTypeNameEditPart;
import reamodel.diagram.edit.parts.ProvideLabelEditPart;
import reamodel.diagram.edit.parts.ProvideParticipationEditPart;
import reamodel.diagram.edit.parts.ProvideParticipationNameEditPart;
import reamodel.diagram.edit.parts.REAModelEditPart;
import reamodel.diagram.edit.parts.ReceiveLabelEditPart;
import reamodel.diagram.edit.parts.ReceiveParticipationEditPart;
import reamodel.diagram.edit.parts.ReceiveParticipationNameEditPart;
import reamodel.diagram.edit.parts.ReciprocityLabelEditPart;
import reamodel.diagram.edit.parts.SpecifyLabel2EditPart;
import reamodel.diagram.edit.parts.SpecifyLabel3EditPart;
import reamodel.diagram.edit.parts.SpecifyLabel4EditPart;
import reamodel.diagram.edit.parts.SpecifyLabelEditPart;
import reamodel.diagram.edit.parts.TypifyLabel2EditPart;
import reamodel.diagram.edit.parts.TypifyLabel3EditPart;
import reamodel.diagram.edit.parts.TypifyLabel4EditPart;
import reamodel.diagram.edit.parts.TypifyLabelEditPart;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class REAmetamodelVisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "REAModeller.diagram/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (REAModelEditPart.MODEL_ID.equals(view.getType())) {
				return REAModelEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return reamodel.diagram.part.REAmetamodelVisualIDRegistry
				.getVisualID(view.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				REAmetamodelDiagramEditorPlugin.getInstance().logError(
						"Unable to parse view type as a visualID number: "
								+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return String.valueOf(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (ReamodelPackage.eINSTANCE.getREAModel().isSuperTypeOf(
				domainElement.eClass())
				&& isDiagram((REAModel) domainElement)) {
			return REAModelEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = reamodel.diagram.part.REAmetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!REAModelEditPart.MODEL_ID.equals(containerModelID)) {
			return -1;
		}
		int containerVisualID;
		if (REAModelEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = reamodel.diagram.part.REAmetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = REAModelEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case REAModelEditPart.VISUAL_ID:
			if (ReamodelPackage.eINSTANCE.getEconomicResourceType()
					.isSuperTypeOf(domainElement.eClass())) {
				return EconomicResourceTypeEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getEconomicAgentType().isSuperTypeOf(
					domainElement.eClass())) {
				return EconomicAgentTypeEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getDecrementEconomicEventType()
					.isSuperTypeOf(domainElement.eClass())) {
				return DecrementEconomicEventTypeEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getIncrementEconomicEventType()
					.isSuperTypeOf(domainElement.eClass())) {
				return IncrementEconomicEventTypeEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getEconomicAgent().isSuperTypeOf(
					domainElement.eClass())) {
				return EconomicAgentEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getEconomicResource().isSuperTypeOf(
					domainElement.eClass())) {
				return EconomicResourceEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getDecrementEconomicEvent()
					.isSuperTypeOf(domainElement.eClass())) {
				return DecrementEconomicEventEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getIncrementEconomicEvent()
					.isSuperTypeOf(domainElement.eClass())) {
				return IncrementEconomicEventEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getIncrementCommitment()
					.isSuperTypeOf(domainElement.eClass())) {
				return IncrementCommitmentEditPart.VISUAL_ID;
			}
			if (ReamodelPackage.eINSTANCE.getDecrementCommitment()
					.isSuperTypeOf(domainElement.eClass())) {
				return DecrementCommitmentEditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = reamodel.diagram.part.REAmetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!REAModelEditPart.MODEL_ID.equals(containerModelID)) {
			return false;
		}
		int containerVisualID;
		if (REAModelEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = reamodel.diagram.part.REAmetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = REAModelEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case EconomicResourceTypeEditPart.VISUAL_ID:
			if (EconomicResourceTypeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case EconomicAgentTypeEditPart.VISUAL_ID:
			if (EconomicAgentTypeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DecrementEconomicEventTypeEditPart.VISUAL_ID:
			if (DecrementEconomicEventTypeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementEconomicEventTypeEditPart.VISUAL_ID:
			if (IncrementEconomicEventTypeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case EconomicAgentEditPart.VISUAL_ID:
			if (EconomicAgentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case EconomicResourceEditPart.VISUAL_ID:
			if (EconomicResourceNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DecrementEconomicEventEditPart.VISUAL_ID:
			if (DecrementEconomicEventNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementEconomicEventEditPart.VISUAL_ID:
			if (IncrementEconomicEventNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementCommitmentEditPart.VISUAL_ID:
			if (IncrementCommitmentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DecrementCommitmentEditPart.VISUAL_ID:
			if (DecrementCommitmentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case REAModelEditPart.VISUAL_ID:
			if (EconomicResourceTypeEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (EconomicAgentTypeEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DecrementEconomicEventTypeEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (IncrementEconomicEventTypeEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (EconomicAgentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (EconomicResourceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DecrementEconomicEventEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (IncrementEconomicEventEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (IncrementCommitmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DecrementCommitmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case EconomicResourceTypeTypifyEditPart.VISUAL_ID:
			if (TypifyLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case OutflowEditPart.VISUAL_ID:
			if (OutflowNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (EconomicResourceOutflowLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case InflowEditPart.VISUAL_ID:
			if (InflowNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (EconomicResourceInflowLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DecrementEconomicEventTypeTypifyEditPart.VISUAL_ID:
			if (TypifyLabel2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementEconomicEventTypeTypifyEditPart.VISUAL_ID:
			if (TypifyLabel3EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case OutflowTypeEditPart.VISUAL_ID:
			if (OutflowTypeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (OutflowTypeLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case InflowTypeEditPart.VISUAL_ID:
			if (InflowTypeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (InflowTypeLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case EconomicAgentTypeTypifyEditPart.VISUAL_ID:
			if (TypifyLabel4EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ReceiveParticipationEditPart.VISUAL_ID:
			if (ReceiveParticipationNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ReceiveLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ProvideParticipationEditPart.VISUAL_ID:
			if (ProvideParticipationNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ProvideLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementEconomicEventDualityEditPart.VISUAL_ID:
			if (DualityLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementEconomicEventTypeDualityTypeEditPart.VISUAL_ID:
			if (DualityTypeLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case CommitmentAgentEditPart.VISUAL_ID:
			if (SpecifyLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case CommitmentResourceEditPart.VISUAL_ID:
			if (SpecifyLabel2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementCommitmentFulfillEditPart.VISUAL_ID:
			if (FulfillLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DecrementCommitmentFulfillEditPart.VISUAL_ID:
			if (FulfillLabel2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementCommitmentReciprocityEditPart.VISUAL_ID:
			if (ReciprocityLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DecrementCommitmentSpecifyEditPart.VISUAL_ID:
			if (SpecifyLabel3EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IncrementCommitmentSpecifyEditPart.VISUAL_ID:
			if (SpecifyLabel4EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (ReamodelPackage.eINSTANCE.getOutflow().isSuperTypeOf(
				domainElement.eClass())) {
			return OutflowEditPart.VISUAL_ID;
		}
		if (ReamodelPackage.eINSTANCE.getInflow().isSuperTypeOf(
				domainElement.eClass())) {
			return InflowEditPart.VISUAL_ID;
		}
		if (ReamodelPackage.eINSTANCE.getOutflowType().isSuperTypeOf(
				domainElement.eClass())) {
			return OutflowTypeEditPart.VISUAL_ID;
		}
		if (ReamodelPackage.eINSTANCE.getInflowType().isSuperTypeOf(
				domainElement.eClass())) {
			return InflowTypeEditPart.VISUAL_ID;
		}
		if (ReamodelPackage.eINSTANCE.getReceiveParticipation().isSuperTypeOf(
				domainElement.eClass())) {
			return ReceiveParticipationEditPart.VISUAL_ID;
		}
		if (ReamodelPackage.eINSTANCE.getProvideParticipation().isSuperTypeOf(
				domainElement.eClass())) {
			return ProvideParticipationEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(REAModel element) {
		return true;
	}

}
